<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Index</title>
</head>
<body>
<h1>welcome to admin cilent</h1>
<div id="loginTip"></div>
<p><button onclick="getOrderInfo()">获取订单信息</button></p>

<table>
    <tr><td>order id</td><td><input id="orderId" /></td></tr>
    <tr><td>order product id</td><td><input id="productId" /></td></tr>
</table>




</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
    $(document).ready(function(){

        $.get("/me",function(data,status){
            if(data){
                //已登录
                var htm = "已登录,<a href='/logout'>退出</a>";
                $("#loginTip").html(htm);
            }else{
                //未登录
                var href = "<a href='/'>未登录，去登录</a>";
                $("#loginTip").append(href);
            }
        });
    });

    function getOrderInfo(){
        let access_token = $.cookie('chong_token');
        $.ajax({
            //请求方式
            type : "get",
            contentType: "application/json;charset=UTF-8",
            headers: {
                'Authorization': "Bearer "+access_token,
            },
            url : "api/order/orders/1",
            success : function(data) {
                $("#orderId").val(data.id);
                $("#productId").val(data.productId);
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                alert('获取订单失败！');
            }
        });
    }


</script>
</html>